layui.use(['form','table'],function(){
    var form = layui.form,

        $ = layui.jquery,
        table = layui.table;



    //用户列表
    var tableIns=table.render({

        elem: '#carParkInfoCom',
        url : '/sharepark/community/carPark',
        page : true,
        height : "full-100",
        limits : [10,20,30,40],
        limit : 10,
        id : "carParkInfoCom",
        text:{none:'暂无相关数据'},

        cols : [[
            {type: "checkbox", fixed:"left", width:50},
            {field: 'cNumber', title: '车位号',  align:"center",sort:true},
            {field: 'uName', title: '出租方姓名',align:'center',templet: '<div>{{d.userInfo.uName}}</div>' },
            {field: 'uTel', title: '出租方电话',  align:'center',templet: '<div>{{d.userInfo.uTel}}</div>'},
            {field: 'cAddress', title:'车位位置',  align:'center'},
            {field: 'cStatus', title:'审核状态',  align:'center',sort:true},
            {field: 'cState', title: '租赁状态',  align:'center',sort:true}
            // {title: '操作', minWidth:175, templet:'#userListBar',fixed:"right",align:"center"}
        ]]
    });


    //搜索
    $(".search_btn").on("click",function(){

            tableIns.reload({
                where: {
                    "cNumber": $('.searchVal').val(),
                    "cStatus":$('#cStatus').val(),
                    "cState":$('#cState').val()

                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });

    });

    //批量审核通过
    $(".check_btn").click(function(){
        var checkStatus = table.checkStatus('carParkInfoCom'),
            data = checkStatus.data,
            ids = [];
        console.log(data);
        if(data.length > 0) {

            for (var i=0; i<data.length; i++) {
                if (data[i].cStatus==="通过" || data[i].cStatus==="物业通过"){
                   layer.alert("选中的车位中包括已经审核通过的，请重新选择！");
                    return;
                }
                ids.push(data[i].id);
            }
            layer.confirm('确定审核通过选中的车位？', {icon: 3, title: '提示信息'}, function (index) {
                var param = "params=" + ids;
                $.post("/sharepark/community/check",
                    param,
                    function(data){
                        tableIns.reload();
                        layer.msg("审核通过"+ids.length+"个车位");
                        layer.close(index);
                    })
            })


        }else{
            layer.msg("请选择审核通过的车位");
        }
    })



})
